#include "particle_packing_graphics.h"

namespace Particle_packing
{
	static const GLfloat circle_fill_color[] = {0.7f, 0.7f, 0.7f} ;
	static const GLfloat c1 = 0.35f ;
	static const GLfloat c2 = 0.5f ;
	static const GLfloat c3 = 1.0f ;
	static GLfloat color_table[24][3] = 
	{
		{c3, c2, c2},{c2, c3, c2},{c2, c2, c3},{c2, c3, c3},{c3, c2, c3},{c3, c3, c2},{c1, c2, c2},
		{c2, c1, c2},{c2, c2, c1},{c2, c1, c1},{c1, c2, c1},{c1, c1, c2},{c1, c3, c3},{c3, c1, c3},
		{c3, c3, c1},{c3, c1, c1},{c1, c3, c1},{c1, c1, c3},{c1, c2, c3},{c1, c3, c2},{c2, c1, c3}, 
		{c2, c3, c1},{c3, c1, c2},{c3, c2, c1}
	} ;

	static int random_color_index_ = 0 ;
	static void gl_random_color() {
		glColor3f(
			color_table[random_color_index_][0], 
			color_table[random_color_index_][1], 
			color_table[random_color_index_][2]
		) ;
		random_color_index_ = (random_color_index_ + 1) % 12 ;
	}
	static void gl_random_color(int index) {
		random_color_index_ = index % 12 ;
		gl_random_color() ;
	}
	static void gl_randomize_colors() {
		random_color_index_ = 0 ;
	}
	Particle_packing_graphics::Particle_packing_graphics(Particle_packer* _packer) : packer(_packer)//, show_domain_mesh_(true)
	{

	}
	Particle_packing_graphics::~Particle_packing_graphics()
	{

	}
	void Particle_packing_graphics::draw()
	{
		glUseProgramObjectARB(0);
		
		gl_randomize_colors();
 		
		std::for_each(packer->circles.begin(), packer->circles.end(), std::bind2nd( std::mem_fun_ref(&Particle_circle::gl_draw), circle_fill_color));

		for (unsigned int i = 0; i < packer->circle_unions.size(); i++)
		{
			//gl_random_color(i);
			packer->circle_unions.at(i).gl_draw(color_table[i%24]);
		}
		
		packer->rbox->gl_draw();
	}
}
